package com.woniuxy.woniuticket.moviemodule.service.impl;

import com.woniuxy.woniuticket.moviemodule.dao.CinemaHallDAO;
import com.woniuxy.woniuticket.moviemodule.service.CinemaHallService;
import com.woniuxy.woniuticket.pojo.CinemaHall;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Utopia
 * @title: CinamaHallServiceImpl
 * @projectName woniuticket
 * @description: TODO
 * @date 2019/5/30 17:50
 */

@Service
public class CinemaHallServiceImpl implements CinemaHallService {

    @Resource
    private CinemaHallDAO cinemaHallDAO;


    @Override
    public List<CinemaHall> selectAll(Integer currentPage, Integer pageSize) {
        return cinemaHallDAO.selectAllCinemaHall(currentPage, pageSize);
    }

    @Override
    public CinemaHall selectById(Integer id) {
        return cinemaHallDAO.selectByPrimaryKey(id);
    }

    @Override
    public int upadteCinemaHall(CinemaHall cinemaHall) {
        if (cinemaHall==null || cinemaHall.getId()==null || cinemaHall.getId()==0){
            return 0;
        }
        return cinemaHallDAO.updateByPrimaryKeySelective(cinemaHall);
    }

    @Override
    public int insertCinemaHall(CinemaHall cinemaHall) {
        return cinemaHallDAO.insertSelective(cinemaHall);
    }

    @Override
    public int deleteCinemaHall(String ids) {
        String[] keys = ids.split(",");
        int row = 0;
        for (String id: keys) {
            row += cinemaHallDAO.deleteByPrimaryKey(Integer.parseInt(id));
        }
        if (row==keys.length){
            return 1;
        }
        return 0;
    }

    @Override
    public List<CinemaHall> selectAllHall() {
        return cinemaHallDAO.selectAllCinemaHalls();
    }
}
